home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / control / server / vehicles / car.cs
Text File  |  2006-09-24  |  7KB  |  230 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7.  
  8. // Information extacted from the shape.
  9. //
  10. // Wheel Sequences
  11. //    spring#        Wheel spring motion: time 0 = wheel fully extended,
  12. //                   the hub must be displaced, but not directly animated
  13. //                   as it will be rotated in code.
  14. // Other Sequences
  15. //    steering       Wheel steering: time 0 = full right, 0.5 = center
  16. //    breakLight     Break light, time 0 = off, 1 = breaking
  17. //
  18. // Wheel Nodes
  19. //    hub#           Wheel hub, the hub must be in it's upper position
  20. //                   from which the springs are mounted.
  21. //
  22. // The steering and animation sequences are optional.
  23. // The center of the shape acts as the center of mass for the car.
  24.  
  25. //-----------------------------------------------------------------------------
  26. datablock AudioProfile(CarSoftImpactSound)
  27. {
  28.    filename    = "~/data/sound/vcrunch.ogg";
  29.    description = AudioClose3d;
  30.    preload = true;
  31. };
  32.  
  33. datablock AudioProfile(CarHardImpactSound)
  34. {
  35.    filename    = "~/data/sound/vcrash.ogg";
  36.    description = AudioClose3d;
  37.    preload = true;
  38. };
  39.  
  40. datablock AudioProfile(CarWheelImpactSound)
  41. {
  42.    filename    = "~/data/sound/impact.ogg";
  43.    description = AudioClose3d;
  44.    preload = true;
  45. };
  46.  
  47. datablock AudioProfile(CarThrustSound)
  48. {
  49.    filename    = "~/data/sound/caraccel.ogg";
  50.    description = AudioDefaultLooping3d;
  51.    preload = true;
  52. };
  53.  
  54. datablock AudioProfile(CarEngineSound)
  55. {
  56.    filename    = "~/data/sound/caridle.ogg";
  57.    description = AudioClose3d;
  58.    preload = true;
  59. };
  60.  
  61. datablock AudioProfile(CarSquealSound)
  62. {
  63.    filename    = "~/data/sound/squeal.ogg";
  64.    description = AudioClose3d;
  65.    preload = true;
  66. };
  67.  
  68. datablock ParticleData(TireParticle)
  69. {
  70.    textureName          = "~/data/particles/dustParticle";
  71.    dragCoefficient      = 2.0;
  72.    gravityCoefficient   = -0.1;
  73.    inheritedVelFactor   = 0.1;
  74.    constantAcceleration = 0.0;
  75.    lifetimeMS           = 1000;
  76.    lifetimeVarianceMS   = 0;
  77.    colors[0]     = "0.46 0.36 0.26 1.0";
  78.    colors[1]     = "0.46 0.46 0.36 0.0";
  79.    sizes[0]      = 0.50;
  80.    sizes[1]      = 1.0;
  81. };
  82.  
  83. datablock ParticleEmitterData(TireEmitter)
  84. {
  85.    ejectionPeriodMS = 10;
  86.    periodVarianceMS = 0;
  87.    ejectionVelocity = 1;
  88.    velocityVariance = 1.0;
  89.    ejectionOffset   = 0.0;
  90.    thetaMin         = 5;
  91.    thetaMax         = 20;
  92.    phiReferenceVel  = 0;
  93.    phiVariance      = 360;
  94.    overrideAdvance = false;
  95.    particles = "TireParticle";
  96. };
  97.  
  98.  
  99. //----------------------------------------------------------------------------
  100.  
  101. datablock WheeledVehicleTire(DefaultCarTire)
  102. {
  103.    // Tires act as springs and generate lateral and longitudinal
  104.    // forces to move the vehicle. These distortion/spring forces
  105.    // are what convert wheel angular velocity into forces that
  106.    // act on the rigid body.
  107.    shapeFile = "~/data/models/vehicles/wheel.dts";
  108.    staticFriction = 4;
  109.    kineticFriction = 1.25;
  110.  
  111.    // Spring that generates lateral tire forces
  112.    lateralForce = 18000;
  113.    lateralDamping = 4000;
  114.    lateralRelaxation = 1;
  115.  
  116.    // Spring that generates longitudinal tire forces
  117.    longitudinalForce = 18000;
  118.    longitudinalDamping = 4000;
  119.    longitudinalRelaxation = 1;
  120. };
  121.  
  122. datablock WheeledVehicleSpring(DefaultCarSpring)
  123. {
  124.    // Wheel suspension properties
  125.    length = 0.85;             // Suspension travel
  126.    force = 3000;              // Spring force
  127.    damping = 600;             // Spring damping
  128.    antiSwayForce = 3;         // Lateral anti-sway force
  129. };
  130.  
  131.  
  132.  
  133.  
  134.  
  135. //-----------------------------------------------------------------------------
  136.  
  137. function WheeledVehicleData::create(%block)
  138. {
  139.    %obj = new WheeledVehicle() {
  140.       dataBlock = %block;
  141.       mountable = true;
  142.    };
  143.    return(%obj);
  144. }
  145.  
  146. //-----------------------------------------------------------------------------
  147.  
  148. function WheeledVehicleData::onAdd(%this,%obj)
  149. {
  150.    // Setup the car with some defaults tires & springs
  151.    for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
  152.       %obj.setWheelTire(%i,DefaultCarTire);
  153.       %obj.setWheelSpring(%i,DefaultCarSpring);
  154.       %obj.setWheelPowered(%i,false);
  155.    }
  156.  
  157.    // Steer front tires
  158.    %obj.setWheelSteering(0,1);
  159.    %obj.setWheelSteering(1,1);
  160.  
  161.    // Only power the two rear wheels...
  162.    %obj.setWheelPowered(2,true);
  163.    %obj.setWheelPowered(3,true);
  164. }
  165.  
  166. function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
  167. {
  168.    // Collision with other objects, including items
  169. }
  170.  
  171. datablock WheeledVehicleData(DefaultCar)
  172. {
  173.    category = "Vehicles";
  174.    className = "Car";
  175.    shapeFile = "~/data/models/vehicles/runabout.dts";
  176.    emap = true;
  177.  
  178.    maxDamage = 1.0;
  179.    destroyedLevel = 0.5;
  180.  
  181.    maxSteeringAngle = 0.785;  // Maximum steering angle
  182.    tireEmitter = TireEmitter; // All the tires use the same dust emitter
  183.  
  184.    // 3rd person camera settings
  185.    cameraRoll = true;         // Roll the camera with the vehicle
  186.    cameraMaxDist = 6;         // Far distance from vehicle
  187.    cameraOffset = 1.5;        // Vertical offset from camera mount point
  188.    cameraLag = 0.1;           // Velocity lag of camera
  189.    cameraDecay = 0.75;        // Decay per sec. rate of velocity lag
  190.  
  191.    // Rigid Body
  192.    mass = 200;
  193.    massCenter = "0 -0.5 0";    // Center of mass for rigid body
  194.    massBox = "0 0 0";         // Size of box used for moment of inertia,
  195.                               // if zero it defaults to object bounding box
  196.    drag = 0.6;                // Drag coefficient
  197.    bodyFriction = 0.6;
  198.    bodyRestitution = 0.4;
  199.    minImpactSpeed = 5;        // Impacts over this invoke the script callback
  200.    softImpactSpeed = 5;       // Play SoftImpact Sound
  201.    hardImpactSpeed = 15;      // Play HardImpact Sound
  202.    integration = 4;           // Physics integration: TickSec/Rate
  203.    collisionTol = 0.1;        // Collision distance tolerance
  204.    contactTol = 0.1;          // Contact velocity tolerance
  205.  
  206.    // Engine
  207.    engineTorque = 4000;       // Engine power
  208.    engineBrake = 600;         // Braking when throttle is 0
  209.    brakeTorque = 8000;        // When brakes are applied
  210.    maxWheelSpeed = 30;        // Engine scale by current speed / max speed
  211.  
  212.    // Energy
  213.    maxEnergy = 100;
  214.    jetForce = 3000;
  215.    minJetEnergy = 30;
  216.    jetEnergyDrain = 2;
  217.  
  218.    // Sounds
  219.    engineSound = CarEngineSound;
  220.    jetSound = CarThrustSound;
  221.    squealSound = CarSquealSound;
  222.    softImpactSound = CarSoftImpactSound;
  223.    hardImpactSound = CarHardImpactSound;
  224.    wheelImpactSound = CarWheelImpactSound;
  225. mountPose[0]             = "sitting";///***KCF***24/09/2006 11:53PM
  226. mountPose[1]             = "sitting";///***KCF***24/09/2006 11:53PM
  227. numMountPoints           = 2;///***KCF***24/09/2006 11:53PM
  228.  
  229. };
  230.